﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;


namespace Business
{

    public class UnionMaker : IEqualityComparer<ProjectStatusTaskType>
    {
        private bool _IsAdvisor;
        public bool IsAdvisor
        {
            get { return _IsAdvisor; }
            set
            {
                _IsAdvisor = value;
            }
        }

        public bool Equals(ProjectStatusTaskType x, ProjectStatusTaskType y)
        {
            //Check whether the compared objects reference the same data.
            if (Object.ReferenceEquals(x, y))
                return true;

            //Check whether any of the compared objects is null.
            if (Object.ReferenceEquals(x, null)
                 || Object.ReferenceEquals(y, null))
                return false;

            //Check whether the products' properties are equal.
            if (IsAdvisor)
            {
                return x.AdvisorStepId == y.AdvisorStepId;
            }
            else
            {
                return x.SurveyorStepId == y.SurveyorStepId;
            }
        }


        public int GetHashCode(ProjectStatusTaskType taskType)
        {
            if (IsAdvisor)
            {
                //Check whether the object is null
                if (Object.ReferenceEquals(taskType, null))
                    return 0;

                //Get hash code for the Name field if it is not null.
                int hashAdvisorStep = taskType.AdvisorStepId == null ? 0 : taskType.AdvisorStepId.GetHashCode();



                //Calculate the hash code for the product.
                return hashAdvisorStep;
            }
            else
            {
                //Check whether the object is null
                if (Object.ReferenceEquals(taskType, null))
                    return 0;

                //Get hash code for the Name field if it is not null.
                int hashProductName = taskType.SurveyorStepId == null ? 0 : taskType.SurveyorStepId.GetHashCode();


                //Calculate the hash code for the product.
                return hashProductName;
            }

        }

        public UnionMaker(bool isAdvisor)
        {
            IsAdvisor = isAdvisor;
        }

        public UnionMaker(Guid contractId)
        {

            IsAdvisor = Convert.ToBoolean(TblContract.FetchByID(contractId).ContractType); 
        }

    }
}
